package jman.competition14;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class CommentDao {
	public ArrayList<CommentAnnal> getCommentList() throws SQLException{
		ArrayList<CommentAnnal> CommentList=new ArrayList<CommentAnnal>();
		Dao d=new Dao();
		d.start();
		String sql="select * from commentlist";
		ResultSet rs=d.read(sql);
		while(rs.next()){
			CommentAnnal c=new CommentAnnal(rs.getString(1),rs.getString(2),rs.getInt(3),rs.getInt(4));
			CommentList.add(c);
		}
		d.close();
		return CommentList;
	}
	public boolean addComment(CommentAnnal c){
		boolean flag=false;
		Dao d=new Dao();
		d.start();
		String sql="insert into commentlist (username,comment,passageid) values ('"+c.getUserName()+"','"+c.getComment()+"',"+c.getPassageId()+")";
		flag=d.add(sql);
		d.close();
		return flag;
	}
}
